#!/bin/bash
#output time
date "+%Y-%m-%d %H:%M:%S"

DATE=$(date +%Y%m%d_%H%M%S)
BASE_DIR="/data1/Projects/science_popularization_project/backup_db/mysql"
DB_HOST="rm-bp151dcc75aycqd80to.mysql.rds.aliyuncs.com"
DATABASE="sciencepopdb"
DB_USER="root"
DB_PASS="Iscas123"
FILE_NAME="${DATABASE}_${DATE}.sql.gz"

# FTP_HOST="192.188.1.106"
# FTP_USER="mysqlbackup"
# FTP_PASS="mysqlbackup"

mysqldump -h${DB_HOST} -u${DB_USER} -p${DB_PASS} ${DATABASE} | gzip > ${BASE_DIR}/${FILE_NAME}
sleep 3

#find ${BASE_DIR}/ -mtime +100 -name "*.sql.gz" -exec rm -rf {} \;
#sleep 3

date "+%Y-%m-%d %H:%M:%S"
echo "DB backup is finished!"
# scp ${BASE_DIR}/${FILE_NAME} root@192.188.1.20:${BASE_DIR}/${FILE_NAME}
